package com.bayi.storage.utils;


/***********************************************************
 * @author ZOUBIN <zoubin1987@foxmail.com>
 * @ClassName: DataUtil
 * @Description: 数据转换工具类
 * @date 2015年5月18日 下午1:21:32
 ************************************************************/
public class DataUtil {


    public static int getInt(String value, int defaultValue) {

        if (StringUtil.isEmpty(value)) {
            return defaultValue;
        }
        try {
            float v = Float.valueOf(value);
            return (int) v;
        } catch (ClassCastException e) {
            return defaultValue;
        }
    }

    public static int [] getIntList(int count,int addNub){
        int[] a = new int[count];
        for (int i=0;i<a.length;i++){
            a[i]=i+1+addNub;
        }
        return a;
    }

    public static String getType(String a) {
        String type = "未知";
        switch (a) {
            case "ils":
                type = "灯光";
                break;
            case "acs":
                type = "门禁";
                break;
            case "vms":
                type = "视频";
                break;
            case "dms":
                type = "光盘";
                break;
            case "ims":
                type = "密集架";
                break;
            case "hcs":
                type = "温湿度";
                break;
            case "rfid":
                type = "RFID";
                break;

        }
        return type;
    }

    public static String   ridZeroForString(String str){
        if(str!=null){
            if(str.indexOf(".0")>0){
                str=str.replace(".0","");
            }
        }
        return str;
    }



    public static void intMppx(int a[],boolean isDsc) {
        //冒泡排序
        for (int k = 0; k < a.length - 1; k++) {
            for (int j = k + 1; j < a.length; j++) {
                // 升序把<改成>
                if (isDsc) {
                    if (a[k] < a[j]) {
                        int temp = a[k];
                        a[k] = a[j];
                        a[j] = temp;
                    }
                } else {
                    if (a[k] > a[j]) {
                        int temp = a[k];
                        a[k] = a[j];
                        a[j] = temp;
                    }
                }
            }
        }

    }

}
